package com.dianping.cat.configuration.server.filter.transform;

import com.dianping.cat.configuration.server.filter.IVisitor;
import com.dianping.cat.configuration.server.filter.entity.AtomicTreeConfig;
import com.dianping.cat.configuration.server.filter.entity.CrashLogDomain;
import com.dianping.cat.configuration.server.filter.entity.ServerFilterConfig;
import java.util.Stack;





public class DefaultValidator
  implements IVisitor
{
/* 16 */   private Path m_path = new Path();
  
  protected void assertRequired(String name, Object value) {
/* 19 */     if (value == null) {
/* 20 */       throw new RuntimeException(String.format("%s at path(%s) is required!", new Object[] { name, this.m_path }));
    }
  }


  
  public void visitAtomicTreeConfig(AtomicTreeConfig atomicTreeConfig) {}

  
  public void visitCrashLogDomain(CrashLogDomain crashLogDomain) {
/* 30 */     this.m_path.down("crash-log-domain");

/* 32 */     assertRequired("id", crashLogDomain.getId());

/* 34 */     this.m_path.up("crash-log-domain");
  }

  
  public void visitServerFilterConfig(ServerFilterConfig serverFilterConfig) {
/* 39 */     this.m_path.down("server-filter-config");

/* 41 */     visitServerFilterConfigChildren(serverFilterConfig);

/* 43 */     this.m_path.up("server-filter-config");
  }
  
  protected void visitServerFilterConfigChildren(ServerFilterConfig serverFilterConfig) {
/* 47 */     for (CrashLogDomain crashLogDomain : serverFilterConfig.getCrashLogDomains().values()) {
/* 48 */       visitCrashLogDomain(crashLogDomain);
    }
    
/* 51 */     if (serverFilterConfig.getAtomicTreeConfig() != null)
/* 52 */       visitAtomicTreeConfig(serverFilterConfig.getAtomicTreeConfig()); 
  }
  
  static class Path
  {
/* 57 */     private Stack<String> m_sections = new Stack();
    
    public Path down(String nextSection) {
/* 60 */       this.m_sections.push(nextSection);

/* 62 */       return this;
    }

    
    public String toString() {
/* 67 */       StringBuilder sb = new StringBuilder();

/* 69 */       for (String section : this.m_sections) {
/* 70 */         sb.append('/').append(section);
      }
      
/* 73 */       return sb.toString();
    }
    
    public Path up(String currentSection) {
/* 77 */       if (this.m_sections.isEmpty() || !((String)this.m_sections.peek()).equals(currentSection)) {
/* 78 */         throw new RuntimeException("INTERNAL ERROR: stack mismatched!");
      }
      
/* 81 */       this.m_sections.pop();
/* 82 */       return this;
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/server/filter/transform/DefaultValidator.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */